package fundamental;
import java.util.*;
import log.WriteToLog;
import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.Admin;
import singleobject.MemoryInfo;

/**
 * Created by yi on 2017/7/4.
 */
public class Task {
    //only one private member:taskRS,it shows the task's ID and its corresponding
    //key为taskID，value为RS.
    private static Map<String,String> taskRS=new HashMap<String,String>();
    //four methods to operate the map:add,remove,get,set
    //张欣使用，根据taskID得到RS名字
    public String getTheTaskRS(String taskID) {
        return taskRS.get(taskID);
    }
    //陈祥使用，当任务到来时增加taskID及其对应机器。
    public void addTaskRS(String taskID,String host){
        WriteToLog.write("Task:"+taskID+" come,the host:"+host+"\n");
        String RS=new String();
        for(String name: MemoryInfo.getRegionServer().rsNameInCluster){
            if(name.contains(host)){
                RS=name;
            }
        }

        taskRS.put(taskID,RS);

    }
    //不知道谁使用，当任务完成后，移除该任务。
    public void removeTaskRS(String taskID){
        WriteToLog.write("Task:"+taskID+" finish\n");
        taskRS.remove(taskID);
    }

    public boolean isDataLocaility(String taskID,String tableName,String startKey,String endKey){
    String taskToRS;
    String taskRegionToRS;
    taskToRS=MemoryInfo.getTASK().getTheTaskRS(taskID);
    taskRegionToRS=MemoryInfo.getREGION().searchregionTask(tableName, startKey, endKey);
    if(taskToRS.equals(taskRegionToRS)){
        return true;
    }else{
        return false;
    }
    }
}